#!/usr/bin/env python

import urllib2
import time
 
fw = open('stratReport.txt', 'w')
fw.write('header for strat evaluation results text file\n')
#for line in ['ALTR', 'MSFT', 'XLNX']:
for line in ['ALTR']:
    symbol = line.strip()
    yahooApi = 'http://ichart.finance.yahoo.com/table.csv?s=%s&a=03&b=12&c=2009&d=25&e=11&f=2010&g=d&ignore=.csv' % symbol
    try:
        c = urllib2.urlopen(yahooApi)
    except:
        print "error grabbing %s" % symbol
        continue

    firstLine = True
    for dataLine in c.read().split('\n'):
        if firstLine:
            firstLine = False   #skip the first line
            continue
        dataList = dataLine.split(',')

        print dataList

        if len(dataList) < 7: continue  #skip empty lines
    #here you put in your strategy evaluation code
    outPutStr = 'results from your strategy'
    print outPutStr
    fw.write('%s\n' % outPutStr)
    # time.sleep(1) #delay 1 second to be polite to Yahoo
fw.close()
print "quotes done."
